
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
  return typeof t;
} : function(t) {
  return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
}, _tools = require("../../utils/tools"), _util = require("../../utils/util");

function _defineProperty(t, e, o) {
  return e in t ? Object.defineProperty(t, e, {
      value: o,
      enumerable: !0,
      configurable: !0,
      writable: !0
  }) : t[e] = o, t;
}

var g, pages, app = getApp(), page = app.page, request = app.util.request, route = app.route,toast = app.toast;;
// member/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    list: [],
    current: 0,
    equity: [],
    agreement: false,
    nav: 0
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    g = this;
    let userInfo = wx.getStorageSync("userInfo")
      g.setData({
        userInfo
      })
      request({
        url: "MemberShipList",
        showLoading: !1,
        data: {
            
        },
        success: function(t) {
          g.setData({
            list: t,
            equity:  t[0].equity || []
          })
        }
      })
      request({
        url: "Openid",
        showLoading: !1,
        data: {
            user_id: g.data.userInfo.id
        },
        success: function(t) {
          g.setData({
            userInfo: t
          })
        }
      })
  },
  changeNav(e){
    let nav = e.currentTarget.dataset.index
    g.setData({
      nav
    })
  },
  onAgreement(){
    g.setData({
      agreement: !g.data.agreement
     })
  },
  onOpen(){
    wx.pageScrollTo({
      scrollTop: 200, // 滚动到的位置（距离顶部 px）
      duration: 0 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
    })
  },
  selectGood(e){
    let current = e.currentTarget.dataset.index
     g.setData({
      current,
      equity:  g.data.list[current].equity || []
     })
  },
  submit(){
    if(!g.data.agreement){
      toast("阅读并同意会员服务协议");
      return false
    }
    request({
      url: "MemberOrderPay",
      data: {
        order_id:  g.data.list[g.data.current].id,
        user_id: g.data.userInfo.id
      },
      success: function(t) {
          delete t._code
          t.appId ? (0, _tools.wxPay)({
              data: t,
              success: function(t) {
                toast("开通成功");
                request({
                  url: "Openid",
                  showLoading: !1,
                  data: {
                      user_id: g.data.userInfo.id
                  },
                  success: function(t) {
                    g.setData({
                      userInfo: t
                    })
                    wx.redirectTo({
                      url: '/member/vip/vip',
                    })
                  }
                })
              }
          }) : toast("错误:" + t);
      }
  });
  
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  goAgreement(){
    request({
      url: "MembershipAgreement",
      showLoading: !1,
      data: {},
      success: function(t) {
        app.centent = t
        wx.navigateTo({
          url: '/u_pages/html_page/index?title=会员服务协议',
        })
      }
    })
    
  }
})